package com.woniuxy.life.core.api;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 公共响应数据实体类
 * @author admin
 * @param <T>
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommonResult<T> {
    private Long code;
    private String message;
    private T data;


    public CommonResult(Long code, String message) {
        this.code = code;
        this.message = message;
    }


    public static <T> CommonResult<T> success(T data){
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),data);
    }

    public static <T> CommonResult<T> success(){
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage());
    }

    public static <T> CommonResult<T> validateMethodFailed(){
        return new CommonResult<T>
                (ResultCode.VALIDATE_METHOD_FAILED.getCode(),
                        ResultCode.VALIDATE_METHOD_FAILED.getMessage());
    }

    public static <T> CommonResult<T> failed(IErrorCode iErrorCode){
        return new CommonResult<T>(iErrorCode.getCode()
                ,iErrorCode.getMessage());
    }


    public static CommonResult failed(String message){
        return new CommonResult(ResultCode.FAILED.getCode(),message);
    }
    public static <T> CommonResult<T> failed(Long code,String message){
        return new CommonResult<T>(code,message);
    }

    public static <T> CommonResult<T>  failed(){
        return failed(ResultCode.FAILED);
    }

    public static <T> CommonResult<T> methodArgumentValidFailed(String message){
        return new CommonResult<T>(ResultCode.METHOD_ARGUMENT_NOT_VALID.getCode(),
                message);
    }

    public static <T> CommonResult<T> validateFailed(){
        return new CommonResult<T>
                (ResultCode.VALIDATE_FAILED.getCode(),
                        ResultCode.VALIDATE_FAILED.getMessage());
    }
}
